package com.sicong.common.security.entryPoint;

import com.sicong.common.core.enums.ResultEnum;
import com.sicong.common.core.utils.ResponseUtil;
import com.sicong.common.core.utils.ResultUtil;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 未授权统一处理
 *
 * @author chenww
 * @date 2020-11-24
 */
public class UnAuthenticateEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
                         AuthenticationException e) throws IOException, ServletException {
        ResponseUtil.out(httpServletResponse, ResultUtil.error(ResultEnum.UN_AUTH));
    }
}
